require "rubygems"
require "mysql"

stars = File.open("stars.csv", "r")

begin
  dbh = Mysql.real_connect("localhost", "root", "rational", "exo_development")
  rows = stars.collect do |star|
    star = star.split(",")
    ("(\"Ryan Haynes\", #{star[0].to_i}, #{star[1].to_f}, \"#{star[2]}\", #{star[6].to_f}, #{star[8].to_f}, #{star[12].to_f}, \"#{star[13]}\")")
  end
  sql = "INSERT INTO systems (created_by, hd_number, hip_number, name, velocity,effective_temperature, mass, reference) VALUES"  
  sql << rows.join(',')
  dbh.query(sql)
  p "Number of rows affected: #{dbh.affected_rows}"
end
             

